import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;

public class WF {
    public static void main(String[] args) {
        // 验证命令行参数
        if (args.length != 2 || !args[0].equals("-c")) {
            System.err.println("用法: wf.exe -c <file name>");
            System.exit(1);
        }

        String fileName = args[1];
        int[] counts = new int[26]; // 存储a-z的计数
        long totalLetters = 0;

        try (BufferedReader reader = Files.newBufferedReader(Paths.get(fileName), StandardCharsets.UTF_8)) {
            int c;
            // 逐个字符读取，减少内存占用
            while ((c = reader.read()) != -1) {
                char ch = (char) c;
                // 转换为小写字母判断
                if (Character.isLetter(ch)) {
                    int idx = Character.toLowerCase(ch) - 'a';
                    counts[idx]++;
                    totalLetters++;
                }
            }
        } catch (IOException e) {
            System.err.println("文件处理错误: " + e.getMessage());
            System.exit(1);
        }

        // 处理没有字母的情况
        if (totalLetters == 0) {
            System.out.println("文件中未找到任何字母");
            return;
        }

        // 构建字母-频率映射
        List<Map.Entry<Character, Double>> frequencyList = new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            char letter = (char) ('A' + i); // 输出大写字母
            double frequency = (double) counts[i] / totalLetters * 100;
            frequencyList.add(new AbstractMap.SimpleEntry<>(letter, frequency));
        }

        // 排序：先按频率降序，再按字母升序
        frequencyList.sort((e1, e2) -> {
            int freqCompare = Double.compare(e2.getValue(), e1.getValue());
            return freqCompare != 0 ? freqCompare : e1.getKey().compareTo(e2.getKey());
        });

        // 输出结果（保留两位小数）
        for (Map.Entry<Character, Double> entry : frequencyList) {
            System.out.printf("%c: %.2f%%\n", entry.getKey(), entry.getValue());
        }
    }
}